package com.shangdiao.sd_server.server.controller;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shangdiao.sd_server.constant.Constant;
import com.shangdiao.sd_server.constant.ErrorCode;
import com.shangdiao.sd_server.constant.TableConstant;
import com.shangdiao.sd_server.generator.pojo.SdAdmin;
import com.shangdiao.sd_server.generator.pojo.SdAdminExample;
import com.shangdiao.sd_server.generator.pojo.SdCertificate;
import com.shangdiao.sd_server.generator.pojo.SdCertificateExample;
import com.shangdiao.sd_server.generator.pojo.SdCompany;
import com.shangdiao.sd_server.generator.pojo.SdCompanyBase;
import com.shangdiao.sd_server.generator.pojo.SdCompanyBaseExample;
import com.shangdiao.sd_server.generator.pojo.SdCompanyExample;
import com.shangdiao.sd_server.generator.pojo.SdCompanyPhoto;
import com.shangdiao.sd_server.generator.pojo.SdCompanyPhotoExample;
import com.shangdiao.sd_server.generator.pojo.SdDicCompanyField;
import com.shangdiao.sd_server.generator.pojo.SdDicCompanyFieldExample;
import com.shangdiao.sd_server.generator.pojo.SdDicDistrict;
import com.shangdiao.sd_server.generator.pojo.SdDicDistrictExample;
import com.shangdiao.sd_server.generator.pojo.SdDicEducation;
import com.shangdiao.sd_server.generator.pojo.SdDicEducationExample;
import com.shangdiao.sd_server.generator.pojo.SdDicInternshipField;
import com.shangdiao.sd_server.generator.pojo.SdDicInternshipFieldExample;
import com.shangdiao.sd_server.generator.pojo.SdDicParttimeField;
import com.shangdiao.sd_server.generator.pojo.SdDicParttimeFieldExample;
import com.shangdiao.sd_server.generator.pojo.SdDicUniversity;
import com.shangdiao.sd_server.generator.pojo.SdEduExp;
import com.shangdiao.sd_server.generator.pojo.SdEduExpExample;
import com.shangdiao.sd_server.generator.pojo.SdInExp;
import com.shangdiao.sd_server.generator.pojo.SdInExpExample;
import com.shangdiao.sd_server.generator.pojo.SdInternship;
import com.shangdiao.sd_server.generator.pojo.SdInternshipExample;
import com.shangdiao.sd_server.generator.pojo.SdInternshipReview;
import com.shangdiao.sd_server.generator.pojo.SdInternshipReviewExample;
import com.shangdiao.sd_server.generator.pojo.SdLabel;
import com.shangdiao.sd_server.generator.pojo.SdLabelExample;
import com.shangdiao.sd_server.generator.pojo.SdOutExp;
import com.shangdiao.sd_server.generator.pojo.SdOutExpExample;
import com.shangdiao.sd_server.generator.pojo.SdPCollection;
import com.shangdiao.sd_server.generator.pojo.SdPCollectionExample;
import com.shangdiao.sd_server.generator.pojo.SdPInternship;
import com.shangdiao.sd_server.generator.pojo.SdPInternshipExample;
import com.shangdiao.sd_server.generator.pojo.SdPParttime;
import com.shangdiao.sd_server.generator.pojo.SdPParttimeExample;
import com.shangdiao.sd_server.generator.pojo.SdParttime;
import com.shangdiao.sd_server.generator.pojo.SdParttimeExample;
import com.shangdiao.sd_server.generator.pojo.SdParttimeReview;
import com.shangdiao.sd_server.generator.pojo.SdParttimeReviewExample;
import com.shangdiao.sd_server.generator.pojo.SdPerson;
import com.shangdiao.sd_server.generator.pojo.SdPersonBase;
import com.shangdiao.sd_server.generator.pojo.SdPersonBaseExample;
import com.shangdiao.sd_server.generator.pojo.SdPersonExample;
import com.shangdiao.sd_server.generator.pojo.SdPersonPhoto;
import com.shangdiao.sd_server.generator.pojo.SdPersonPhotoExample;
import com.shangdiao.sd_server.pojo.ResponseMsg;
import com.shangdiao.sd_server.pojo.Row;
import com.shangdiao.sd_server.service.AdminService;
import com.shangdiao.sd_server.service.CompanyService;
import com.shangdiao.sd_server.service.DicService;
import com.shangdiao.sd_server.service.PersonService;
import com.shangdiao.sd_server.service.PostService;
import com.shangdiao.sd_server.service.RedisService;
import com.shangdiao.sd_server.service.SequenceService;
import com.shangdiao.sd_server.util.CommonUtil;
import com.shangdiao.sd_server.util.DateUtil;
import com.shangdiao.sd_server.util.JsonUtil;
import com.shangdiao.sd_server.util.MD5Util;
import com.shangdiao.sd_server.util.RequestUtil;
import com.shangdiao.sd_server.util.StringUtil;


@Controller
@RequestMapping( "/server" )
public class ServerController {

	@Autowired
	CompanyService companyService;
	@Autowired
	PostService postService;
	@Autowired
	PersonService personService;
	@Autowired
	RedisService redisService;
	@Autowired
	DicService dicService;
	@Autowired
	SequenceService sequenceService;
	@Autowired
	AdminService adminService;
	
	@RequestMapping(value = { "/selectCompany.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectCompany(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			String companyName = RequestUtil.get(request, "companyName", "");
			String tel = RequestUtil.get(request, "tel", "");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			SdCompanyExample example = new SdCompanyExample();
			if(!StringUtil.isBlank(companyName) && !StringUtil.isBlank(tel)){
				example.or().andCompanyNameLike("%" + companyName + "%")
					.andTelLike("%" + tel + "%")
					.andDelEqualTo(Constant.DEL_NO);
			}else if(StringUtil.isBlank(companyName) && !StringUtil.isBlank(tel)){
				example.or().andTelLike("%" + tel + "%")
				.andDelEqualTo(Constant.DEL_NO);
			}else if(!StringUtil.isBlank(companyName) && StringUtil.isBlank(tel) ){
				example.or().andCompanyNameLike("%" + companyName + "%")
				.andDelEqualTo(Constant.DEL_NO);
			}else if(StringUtil.isBlank(companyName) && StringUtil.isBlank(tel)){
				example.or()
				.andDelEqualTo(Constant.DEL_NO);
			}
			example.setOrderByClause("create_date desc limit " + start + "," + pageSize);
			List<SdCompany> companyList = companyService.selectCompanyByExample(example);
			List<Row> resultList = new ArrayList<Row>();
			for(SdCompany company : companyList){
				Row result = new Row();
				Integer companyId = company.getCompanyId();
				SdCompanyBase companyBase = companyService.selectCompanyBaseById(companyId);
				result.put("companyId", company.getCompanyId());
				result.put("companyName", company.getCompanyName());
				String dicFieldName = company.getDicFieldName();
				if(StringUtil.isBlank(dicFieldName)){
					result.put("dicFieldName", "");
				}else{
					result.put("dicFieldName", dicFieldName);
				}
				result.put("districtId", company.getDistrictId());
				result.put("district", company.getDistrict() == null ? "" : company.getDistrict());
				result.put("location", company.getLocation() == null ? "" : company.getLocation());
				String email = company.getEmail();
				if(StringUtil.isBlank(email)){
					result.put("email", "");
				}else{
					result.put("email", email);
				}
				result.put("tel", company.getTel());
				if(companyBase != null && companyBase.getStatus() == 1){
					result.put("status", "是");
				}else{
					result.put("status", "否");
				}
				
				resultList.add(result);
			}
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, resultList);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectCompanyDetail.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectCompanyDetail(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			Row result = new Row();
			SdCompany company = companyService.selectCompanyById(companyId);
			result.put("companyId", companyId);
			result.put("companyName", company.getCompanyName());
			result.put("dicFieldId", company.getDicFieldId());
			result.put("dicFieldName", company.getDicFieldName());
			result.put("website", company.getWebsite());
			Integer districtId = company.getDistrictId();
			if(districtId != null){
				result.put("provinceId", (districtId / 10000) * 10000);
				result.put("cityId", (districtId / 100) * 100);
				result.put("districtId", districtId);
			}
			result.put("district", company.getDistrict() == null ? "" : company.getDistrict());
			result.put("location", company.getLocation() == null ? "" : company.getLocation());
			result.put("email", company.getEmail());
			result.put("tel", company.getTel());
			result.put("intro", company.getIntro());
			String logo = company.getLogo();
			if(!StringUtil.isBlank(logo)){
				result.put("logo", "http://139.196.20.115" + logo + "?h=136&w=136");
			}
			result.put("createDate", DateUtil.DateToString(company.getCreateDate(), DateUtil.FORMAT_ONE));
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, result);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/saveCompanyLogo.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg saveCompanyLogo(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			String logo = RequestUtil.get(request, "logo");
			System.out.println("companyId......................" + companyId);
			System.out.println("logo......................" + logo);
			if(StringUtil.isBlank(logo)){
				return new ResponseMsg("缺少参数", ErrorCode.ERROR, null);
			}else{
				boolean logoFlag = true;
				logo = logo.substring(logo.lastIndexOf("/") + 1, logo.length());
				logoFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + logo, Constant.LOGO_FILE_PATH + logo);
				if(logoFlag){
					SdCompany company = companyService.selectCompanyById(companyId);
					company.setLogo(Constant.LOGO_FILE_URL + logo);
					System.out.println("company .>>> >>> " + JsonUtil.objectToJsonStr(company));
					companyService.updateCompanyById(company);
					return new ResponseMsg("保存成功", ErrorCode.OK, null);
				}
				return new ResponseMsg("保存失败", ErrorCode.ERROR, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectCompanyLogo.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectCompanyLogo(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			Row result = new Row();
			SdCompany company = companyService.selectCompanyById(companyId);
			String logo = company.getLogo();
			if(!StringUtil.isBlank(logo)){
				result.put("logo", "http://139.196.20.115" + logo + "?h=136&w=136");
			}
			SdCompanyPhotoExample example = new SdCompanyPhotoExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_time desc");
			List<SdCompanyPhoto> photoList = companyService.selectCompanyPhoto(example);
			List<Row> photo_list = new ArrayList<Row>();
			for(SdCompanyPhoto companyphoto : photoList){
				Row photo = new Row();
				photo.put("photoId", companyphoto.getCompanyPhotoId());
				photo.put("photoUrl", "http://139.196.20.115" + companyphoto.getCompanyPhotoUrl() + "?h=136&w=136");
				photo_list.add(photo);
			}
			result.put("photoList", photo_list);
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, result);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectInternshipList.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectInternshipList(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			SdCompany company = companyService.selectCompanyById(companyId);
			List<Row> resultList = new ArrayList<Row>();
			SdInternshipExample example = new SdInternshipExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_date desc limit " + start + "," + pageSize);
			List<SdInternship> internshipList = postService.selectInternshipList(example);
			for(SdInternship internship : internshipList){
				Row result = new Row();
				result.put("companyName", company.getCompanyName());
				result.put("postId", internship.getInternshipId());
				result.put("internshipName", internship.getInternshipName());
				result.put("dicInternshipFieldName", internship.getDicInternshipFieldName());
				result.put("salary", internship.getMinSalary() + "K ~ " + internship.getMaxSalary() + "K");
				String district = internship.getDistrict();
				if(StringUtil.isBlank(district)){
					result.put("district", "");
				}else{
					result.put("district", district);
				}
				String tel = internship.getTel();
				if(StringUtil.isBlank(tel)){
					result.put("tel", "");
				}else{
					result.put("tel", tel);
				}
				result.put("postFlag", Constant.POST_FLAG_INTERNSHIP);
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectParttimeList.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectParttimeList(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			SdCompany company = companyService.selectCompanyById(companyId);
			List<Row> resultList = new ArrayList<Row>();
			SdParttimeExample example = new SdParttimeExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdParttime> parttimeList = postService.selectParttimeList(example);
			for(SdParttime parttime : parttimeList){
				Row result = new Row();
				result.put("companyName", company.getCompanyName());
				result.put("postId", parttime.getParttimeId());
				result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
				result.put("recruitingNumbers", parttime.getRecruitingNumbers());
				result.put("dicSettlementName", parttime.getDicSettlementName());
				result.put("district", parttime.getDistrict());
				result.put("tel", parttime.getTel());
				result.put("postFlag", Constant.POST_FLAG_PARTTIME);
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectPostDetail.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPostDetail(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer postId = RequestUtil.getInt(request, "postId");
			Integer postFlag = RequestUtil.getInt(request, "postFlag");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			Row result = new Row();
			if(postFlag == Constant.POST_FLAG_INTERNSHIP){
				SdInternship internship = postService.selectInternship(postId);
				result.put("postId", internship.getInternshipId());
				result.put("postFlag", Constant.POST_FLAG_INTERNSHIP);
				result.put("companyId", internship.getCompanyId());
				result.put("postId", internship.getInternshipId());
				result.put("internshipName", internship.getInternshipName());
				result.put("dicInternshipFieldId", internship.getDicInternshipFieldId());
				result.put("dicInternshipFieldName", internship.getDicInternshipFieldName());
				result.put("minSalary", internship.getMinSalary());
				result.put("maxSalary", internship.getMaxSalary());
				result.put("minEducationId", internship.getMinEducationId());
				result.put("minEducationName", internship.getMinEducationName());
				result.put("recruitingNumbers", internship.getRecruitingNumbers());
				Integer districtId = internship.getDistrictId();
				if(districtId != null){
					result.put("provinceId", (districtId / 10000) * 10000);
					result.put("cityId", (districtId / 100) * 100);
					result.put("districtId", districtId);
				}
				result.put("district", internship.getDistrict());
				result.put("location", internship.getLocation());
				result.put("description", internship.getDescription());
				result.put("requirement", internship.getRequirement());
				result.put("tel", internship.getTel());
				result.put("createDate", DateUtil.DateToString(internship.getCreateDate(), DateUtil.FORMAT_ONE));
				SdInternshipReviewExample example = new SdInternshipReviewExample();
				example.or().andInternshipIdEqualTo(postId)
					.andDelEqualTo(Constant.DEL_NO);
				example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
				List<SdInternshipReview> reviewList = postService.selectInternshipReview(example);
				List<Row> rowList = new ArrayList<Row>();
				for(SdInternshipReview review : reviewList){
					Integer personId = review.getPersionId();
					SdPersonBase personBase = personService.selectPersonBaseById(personId);
					Row row = new Row();
					row.put("personName", personBase.getPersonName());
					row.put("review", review.getReview());
					row.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
					rowList.add(row);
				}
				result.put("reviewList", rowList);
			}else if(postFlag == Constant.POST_FLAG_PARTTIME){
				SdParttime parttime = postService.selectParttime(postId);
				result.put("postId", parttime.getParttimeId());
				result.put("postFlag", Constant.POST_FLAG_PARTTIME);
				result.put("companyId", parttime.getCompanyId());
				result.put("dicParttimeFieldId", parttime.getDicParttimeFieldId());
				result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
				result.put("recruitingNumbers", parttime.getRecruitingNumbers());
				result.put("dicSettlementId", parttime.getDicSettlementId());
				result.put("dicSettlementName", parttime.getDicSettlementName());
				result.put("hasAllowance", parttime.getHasAllowance() == Constant.DEL_NO ? "无" : "有");
				result.put("hasAllowanceFlag", parttime.getHasAllowance());
				result.put("salary", parttime.getSalary() + "/" + parttime.getUnit());
				result.put("salaryNum", parttime.getSalary());
				result.put("unit", parttime.getUnit());
				result.put("workDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.SHORT_DATE_FORMAT) + "至" + DateUtil.DateToString(parttime.getEndData(), DateUtil.SHORT_DATE_FORMAT)); 
				result.put("startDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.EXTRA_DATE_FORMAT)); 
				result.put("endDate", DateUtil.DateToString(parttime.getEndData(), DateUtil.EXTRA_DATE_FORMAT)); 
				result.put("workTime", DateUtil.DateToString(parttime.getStartTime(), DateUtil.LONG_TIME_MINUTE_FORMAT) + "-" + DateUtil.DateToString(parttime.getEndTime(), DateUtil.LONG_TIME_MINUTE_FORMAT));
				result.put("startTime", DateUtil.DateToString(parttime.getStartTime(), DateUtil.LONG_TIME_MINUTE_FORMAT));
				result.put("endTime", DateUtil.DateToString(parttime.getEndTime(), DateUtil.LONG_TIME_MINUTE_FORMAT));
				Integer districtId = parttime.getDistrictId();
				if(districtId != null){
					result.put("provinceId", (districtId / 10000) * 10000);
					result.put("cityId", (districtId / 100) * 100);
					result.put("districtId", districtId);
				}
				result.put("district", parttime.getDistrict());
				result.put("location", parttime.getLocation());
				result.put("description", parttime.getDescription());
				result.put("deadline", DateUtil.DateToString(parttime.getDeadline(), DateUtil.LONG_DATE_FORMAT));
				result.put("deadlineExtra", DateUtil.DateToString(parttime.getDeadline(), DateUtil.EXTRA_DATE_FORMAT));
				result.put("tel", parttime.getTel());
				result.put("requirement", parttime.getRequirement());
				result.put("createTime", parttime.getCreateTime());
				SdParttimeReviewExample example = new SdParttimeReviewExample();
				example.or().andParttimeIdEqualTo(postId)
					.andDelEqualTo(Constant.DEL_NO);
				example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
				List<SdParttimeReview> reviewList = postService.selectParttimeReview(example);
				List<Row> rowList = new ArrayList<Row>();
				for(SdParttimeReview review : reviewList){
					Integer personId = review.getPersionId();
					SdPersonBase personBase = personService.selectPersonBaseById(personId);
					Row row = new Row();
					row.put("personName", personBase.getPersonName());
					row.put("review", review.getReview());
					row.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
					rowList.add(row);
				}
				result.put("reviewList", rowList);
			}
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, result);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/saveInternshipDetail.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg saveInternshipDetail(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer internshipId = RequestUtil.getInt(request, "internshipId", 0);
			String internshipName = RequestUtil.get(request, "internshipName");
			Integer companyId = RequestUtil.getInt(request, "companyId", 0);
			Integer dicInternshipFieldId = RequestUtil.getInt(request, "dicInternshipFieldId", 0);
			String minSalary = RequestUtil.get(request, "minSalary");
			String maxSalary = RequestUtil.get(request, "maxSalary");
			Integer minEducationId = RequestUtil.getInt(request, "minEducationId", 0);
			String recruitingNumbers = RequestUtil.get(request, "recruitingNumbers");
			Integer districtId = RequestUtil.getInt(request, "districtId", 0);
			String location = RequestUtil.get(request, "location");
			String description = RequestUtil.get(request, "description");
			String requirement = RequestUtil.get(request, "requirement");
			String tel = RequestUtil.get(request, "tel");
			SdInternship internship = new SdInternship();
			if(internshipId != 0){//新建
				internship = postService.selectInternship(internshipId);
			}
			if(!StringUtil.isBlank(internshipName)){
				internship.setInternshipName(internshipName);
			}
			if(dicInternshipFieldId != 0){
				internship.setDicInternshipFieldId(dicInternshipFieldId);
				String dicInternshipFieldName = dicService.selectInternshipField(dicInternshipFieldId).getDicFieldName();
				internship.setDicInternshipFieldName(dicInternshipFieldName);
			}
			if(!StringUtil.isBlank(minSalary) && StringUtil.isNumber(minSalary)){
				internship.setMinSalary(new Double(minSalary));
			}
			if(!StringUtil.isBlank(maxSalary) && StringUtil.isNumber(maxSalary)){
				internship.setMaxSalary(new Double(maxSalary));
			}
			if(minEducationId != 0){
				internship.setMinEducationId(minEducationId);
				String minEducationName = dicService.selectDicEducation(minEducationId).getDicEducationName();
				internship.setMinEducationName(minEducationName);
			}
			if(districtId != 0){
				internship.setDistrictId(districtId);
				Integer provinceId = (districtId / 10000) * 10000;
				Integer cityId = (districtId / 100) * 100;
				String provinceStr = "";
				String cityStr = "";
				String districtStr = "";
				//省
				SdDicDistrict dicDistrict = dicService.selectDistrictById(provinceId);
				if(dicDistrict != null){
					provinceStr = dicDistrict.getDicDistrict();
				}
				//市
				dicDistrict = dicService.selectDistrictById(cityId);
				if(dicDistrict != null){
					cityStr = dicDistrict.getDicDistrict();
				}
				//区
				dicDistrict = dicService.selectDistrictById(districtId);
				if(dicDistrict != null){
					districtStr = dicDistrict.getDicDistrict();
				}
				internship.setDistrict(provinceStr + " " + cityStr + " " + districtStr);
			}
			if(!StringUtil.isBlank(recruitingNumbers) && StringUtil.isNumber(recruitingNumbers)){
				internship.setRecruitingNumbers(Integer.parseInt(recruitingNumbers));
			}
			if(!StringUtil.isBlank(location)){
				internship.setLocation(location);
			}
			if(!StringUtil.isBlank(description)){
				internship.setDescription(description);
			}
			if(!StringUtil.isBlank(requirement)){
				internship.setRequirement(requirement);
			}
			if(!StringUtil.isBlank(tel)){
				internship.setTel(tel);
			}
			if(internshipId != 0){//编辑
				postService.updateInternship(internship);
				return new ResponseMsg("更新实习岗位成功", ErrorCode.OK, null);
			}else{
				internship.setCompanyId(companyId);
				internship.setCreateDate(new Date());
				internship.setStatus(Constant.STATUS_ON);
				postService.insertInternship(internship);
				return new ResponseMsg("新增实习岗位成功", ErrorCode.OK, null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/saveParttimeDetail.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg saveParttimeDetail(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer parttimeId = RequestUtil.getInt(request, "postId", 0);
			Integer companyId = RequestUtil.getInt(request, "companyId", 0);
			Integer dicParttimeFieldId = RequestUtil.getInt(request, "dicParttimeFieldId", 0);
			Integer recruitingNumbers = RequestUtil.getInt(request, "recruitingNumbers", 0);
			Integer dicSettlementId = RequestUtil.getInt(request, "dicSettlementId", 0);
			Integer hasAllowance = RequestUtil.getInt(request, "hasAllowance", 0);
			String salary = RequestUtil.get(request, "salary");
			String unit = RequestUtil.get(request, "unit");
			String startDate = RequestUtil.get(request, "startDate");
			String endDate = RequestUtil.get(request, "endDate");
			String startTime = RequestUtil.get(request, "startTime");
			String endTime = RequestUtil.get(request, "endTime");
			Integer districtId = RequestUtil.getInt(request, "districtId", 0);
			String location = RequestUtil.get(request, "location");
			String description = RequestUtil.get(request, "description");
			String deadline = RequestUtil.get(request, "deadline");
			String requirement = RequestUtil.get(request, "requirement");
			String tel = RequestUtil.get(request, "tel");
			SdParttime parttime = new SdParttime();
			if(parttimeId != 0){//更新
				parttime = postService.selectParttime(parttimeId);
			}
			if(dicParttimeFieldId != 0){
				parttime.setDicParttimeFieldId(dicParttimeFieldId);
				String dicParttimeFieldName = dicService.selectParttimeField(dicParttimeFieldId).getDicFieldName();
				parttime.setDicParttimeFieldName(dicParttimeFieldName);
			}
			if(recruitingNumbers != 0){
				parttime.setRecruitingNumbers(recruitingNumbers);
			}
			if(dicSettlementId != 0){
				parttime.setDicSettlementId(dicSettlementId);
				String dicSettlementName = dicService.selectDicSettlementById(dicSettlementId).getDicSettlementName();
				parttime.setDicSettlementName(dicSettlementName);
			}
			parttime.setHasAllowance(hasAllowance);
			if(!StringUtil.isBlank(salary) && StringUtil.isNumber(salary)){
				parttime.setSalary(salary);
			}
			if(!StringUtil.isBlank(unit)){
				parttime.setUnit(unit);
			}
			if(!StringUtil.isBlank(startDate)){
				parttime.setStartData(DateUtil.StringtoDate(startDate, DateUtil.EXTRA_DATE_FORMAT));
			}
			if(!StringUtil.isBlank(endDate)){
				parttime.setEndData(DateUtil.StringtoDate(endDate, DateUtil.EXTRA_DATE_FORMAT));
			}
			if(!StringUtil.isBlank(startTime)){
				parttime.setStartTime(DateUtil.StringtoDate(startDate + " " + startTime, DateUtil.EXTRA_DATE_FORMAT1));
			}
			if(!StringUtil.isBlank(endTime)){
				parttime.setEndTime(DateUtil.StringtoDate(startDate + " " + endTime, DateUtil.EXTRA_DATE_FORMAT1));
			}
			if(districtId != 0){
				parttime.setDistrictId(districtId);
				Integer provinceId = (districtId / 10000) * 10000;
				Integer cityId = (districtId / 100) * 100;
				String provinceStr = "";
				String cityStr = "";
				String districtStr = "";
				//省
				SdDicDistrict dicDistrict = dicService.selectDistrictById(provinceId);
				if(dicDistrict != null){
					provinceStr = dicDistrict.getDicDistrict();
				}
				//市
				dicDistrict = dicService.selectDistrictById(cityId);
				if(dicDistrict != null){
					cityStr = dicDistrict.getDicDistrict();
				}
				//区
				dicDistrict = dicService.selectDistrictById(districtId);
				if(dicDistrict != null){
					districtStr = dicDistrict.getDicDistrict();
				}
				parttime.setDistrict(provinceStr + " " + cityStr + " " + districtStr);
			}
			if(!StringUtil.isBlank(location)){
				parttime.setLocation(location);
			}
			if(!StringUtil.isBlank(description)){
				parttime.setDescription(description);
			}
			if(!StringUtil.isBlank(requirement)){
				parttime.setRequirement(requirement);
			}
			if(!StringUtil.isBlank(tel)){
				parttime.setTel(tel);
			}
			if(!StringUtil.isBlank(deadline)){
				parttime.setDeadline(DateUtil.StringtoDate(deadline, DateUtil.EXTRA_DATE_FORMAT));
			}
			if(parttimeId != 0){//编辑
				postService.updateParttime(parttime);
				return new ResponseMsg("更新兼职岗位成功", ErrorCode.OK, null);
			}else{
				parttime.setCompanyId(companyId);
				parttime.setCreateTime(new Date());
				parttime.setStatus(Constant.STATUS_ON);
				postService.insertParttime(parttime);
				return new ResponseMsg("新增兼职岗位成功", ErrorCode.OK, null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}

	
	@RequestMapping(value = { "/selectPPostList.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPPostList(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer postId = RequestUtil.getInt(request, "postId", 0);
			Integer postFlag = RequestUtil.getInt(request, "postFlag", 0);
			if(postId == 0 || postFlag == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			List<Row> resultList = new ArrayList<Row>();
			if(postFlag == Constant.POST_FLAG_INTERNSHIP){//实习
				SdPInternshipExample example = new SdPInternshipExample();
				example.or().andInternshipIdEqualTo(postId);
				List<SdPInternship> pInternshipList = postService.selectPInternshipList(example);
				for(SdPInternship pInternship : pInternshipList){
					Integer personId = pInternship.getPersonId();
					SdPerson person = personService.selectPersonById(personId);
					Row result = new Row();
					result.put("p_p_id", pInternship.getpIId());
					result.put("personName", person.getPersonName());
					Date internshipTime = pInternship.getInterviewTime();
					if(internshipTime != null){
						result.put("internshipTime", DateUtil.DateToString(internshipTime, DateUtil.FORMAT_TWO));
					}else{
						result.put("internshipTime", "");
					}
					Date createTime = pInternship.getCreateTime();
					if(createTime != null){
						result.put("createTime", DateUtil.DateToString(createTime, DateUtil.FORMAT_TWO));
					}else{
						result.put("createTime", "");
					}
					Integer status = pInternship.getStatus();
					String statusStr = null;
					switch (status) {
					case 0:
						statusStr = "已申请";
						break;
					case 1:
						statusStr = "已查看";
						break;
					case 2:
						statusStr = "通知面试";
						break;
					case 3:
						statusStr = "已面试";
						break;
					case 4:
						statusStr = "签约上岗";
						break;
					case 5:
						statusStr = "已上班";
						break;
					case 6:
						statusStr = "婉言拒绝";
						break;
					case 7:
						statusStr = "不合适";
						break;
					default:
						break;
					}
					result.put("status", statusStr);
					result.put("source", pInternship.getSource() == Constant.SOURCE_COMPANY ? "企业" : "个人");
					resultList.add(result);
				}
			}else if(postFlag == Constant.POST_FLAG_PARTTIME){//兼职
				SdPParttimeExample example = new SdPParttimeExample();
				example.or().andParttimeIdEqualTo(postId);
				List<SdPParttime> pParttimeList = postService.selectPParttimeList(example);
				for(SdPParttime pParttime : pParttimeList){
					Integer personId = pParttime.getPersonId();
					SdPerson person = personService.selectPersonById(personId);
					Row result = new Row();
					result.put("p_p_id", pParttime.getpPId());
					result.put("personName", person.getPersonName());
					Date internshipTime = pParttime.getInterviewTime();
					if(internshipTime != null){
						result.put("internshipTime", DateUtil.DateToString(internshipTime, DateUtil.FORMAT_TWO));
					}else{
						result.put("internshipTime", "");
					}
					Date createTime = pParttime.getCreateTime();
					if(createTime != null){
						result.put("createTime", DateUtil.DateToString(createTime, DateUtil.FORMAT_TWO));
					}else{
						result.put("createTime", "");
					}
					Integer status = pParttime.getStatus();
					String statusStr = null;
					switch (status) {
					case 0:
						statusStr = "已申请";
						break;
					case 1:
						statusStr = "已查看";
						break;
					case 2:
						statusStr = "通知面试";
						break;
					case 3:
						statusStr = "已面试";
						break;
					case 4:
						statusStr = "签约上岗";
						break;
					case 5:
						statusStr = "已上班";
						break;
					case 6:
						statusStr = "婉言拒绝";
						break;
					case 7:
						statusStr = "不合适";
						break;
					default:
						break;
					}
					result.put("status", statusStr);
					result.put("source", pParttime.getSource() == Constant.SOURCE_COMPANY ? "企业" : "个人");
					resultList.add(result);
				}
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}

	@RequestMapping(value = { "/updatePPost.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg updatePPost(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer p_p_id = RequestUtil.getInt(request, "p_p_id", 0);
			Integer postFlag = RequestUtil.getInt(request, "postFlag", 0);
			Integer status = RequestUtil.getInt(request, "updateStatus");
			String interviewTime = RequestUtil.get(request, "interviewTime");
			if(p_p_id == 0 || postFlag == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			if(postFlag == Constant.POST_FLAG_INTERNSHIP){
				SdPInternship pInternship = new SdPInternship();
				pInternship.setpIId(p_p_id);
				pInternship.setStatus(status);
				pInternship.setInterviewTime(DateUtil.StringtoDate(interviewTime, DateUtil.EXTRA_DATE_FORMAT));
				postService.updatePIntenrship(pInternship);
			}else if(postFlag == Constant.POST_FLAG_PARTTIME){
				SdPParttime pParttime = new SdPParttime();
				pParttime.setpPId(p_p_id);
				pParttime.setStatus(status);
				pParttime.setInterviewTime(DateUtil.StringtoDate(interviewTime, DateUtil.EXTRA_DATE_FORMAT));
				postService.updatePParttime(pParttime);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectPerson.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPerson(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			String personName = RequestUtil.get(request, "personName");
			String tel = RequestUtil.get(request, "tel");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			SdPersonExample example = new SdPersonExample();
			if(!StringUtil.isBlank(personName) && !StringUtil.isBlank(tel)){
				example.or().andPersonNameLike("%" + personName + "%")
					.andTelLike("%" + tel + "%")
					.andDelEqualTo(Constant.DEL_NO);
			}else if(!StringUtil.isBlank(personName) && StringUtil.isBlank(tel)){
				example.or().andPersonNameLike("%" + personName + "%")
				.andDelEqualTo(Constant.DEL_NO);
			}else if(StringUtil.isBlank(personName) && !StringUtil.isBlank(tel)){
				example.or().andTelLike("%" + tel + "%")
				.andDelEqualTo(Constant.DEL_NO);
			}else{
				example.or().andDelEqualTo(Constant.DEL_NO);
			}
			
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdPerson> personList = personService.selectPersonByExample(example);
			List<Row> resultList = new ArrayList<Row>();
			for(SdPerson person : personList){
				Row result = new Row();
				result.put("personId", person.getPersonId());
				result.put("personName", person.getPersonName());
				result.put("personGender", person.getPersonGender() == 1 ? "男" : "女");
				Date birthday = person.getBirthday();
				if(birthday != null){
					result.put("personAge", DateUtil.yearDiffCurr(DateUtil.DateToString(birthday, DateUtil.LONG_DATE_FORMAT)));
				}else{
					result.put("personAge", "");
				}
				result.put("tel", person.getTel());
				String district = person.getDistrict();
				if(!StringUtil.isBlank(district)){
					result.put("district", district);
				}else{
					result.put("district", "");
				}
				resultList.add(result);
			}
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, resultList);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectPersonDetail.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPersonDetail(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer personId = RequestUtil.getInt(request, "personId");
			Row result = new Row();
			SdPerson person = personService.selectPersonById(personId);
			SdPersonBase personBase = personService.selectPersonBaseById(personId);
			result.put("personName", person.getPersonName());
			result.put("personGenderInput", person.getPersonGender());
			result.put("personGender", person.getPersonGender() == 1 ? "男" : "女");
			Date birthday = person.getBirthday();
			if(birthday != null){
				result.put("personAge", DateUtil.yearDiffCurr(DateUtil.DateToString(birthday, DateUtil.LONG_DATE_FORMAT)));
				result.put("birthday", DateUtil.DateToString(birthday, DateUtil.EXTRA_DATE_FORMAT));
			}else{
				result.put("personAge", "");
				result.put("birthday", "");
			}
			result.put("tel", person.getTel());
			result.put("email", person.getEmail());
			Integer districtId = person.getDistrictId();
			result.put("provinceId", (districtId / 10000) * 10000);
			result.put("cityId", (districtId / 100) * 100);
			result.put("districtId", districtId);
			result.put("district", person.getDistrict());
			Integer postFlag = person.getPostFlag();
			if(postFlag != null && postFlag == Constant.POST_FLAG_INTERNSHIP){
				result.put("postFlag", "实习");
			}else{
				result.put("postFlag", "兼职");
			}
			result.put("postFlagInput", postFlag);
			result.put("dicFieldId", person.getDicFieldId());
			result.put("dicFieldName", person.getDicFieldName());
			result.put("universityId", person.getUniversityId());
			result.put("university", person.getUniversity());
			result.put("college", person.getCollege());
			result.put("major", person.getMajor());  //
			Date admissionDate = person.getAdmissionDate();
			if(admissionDate != null){
				result.put("admissionDate", DateUtil.DateToString(admissionDate, DateUtil.EXTRA_DATE_FORMAT));
			}else{
				result.put("admissionDate", "");
			}
			result.put("dicEducationId", person.getDicEducationId());
			result.put("dicEducationName", person.getDicEducationName());
			result.put("selfEvaluation", person.getSelfEvaluation());
			String logo = personBase.getLogo();
			if(!StringUtil.isBlank(logo)){
				result.put("logo", "http://139.196.20.115" + logo + "?h=136&w=136");
			}
			result.put("createTime", DateUtil.DateToString(person.getCreateTime(), DateUtil.FORMAT_ONE));
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, result);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectPersonLogo.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPersonLogo(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer personId = RequestUtil.getInt(request, "personId");
			Row result = new Row();
			SdPersonBase personBase = personService.selectPersonBaseById(personId);
			String logo = personBase.getLogo();
			if(!StringUtil.isBlank(logo)){
				result.put("logo", "http://139.196.20.115" + logo + "?h=136&w=136");
			}
			retMsg = new ResponseMsg("查询成功", ErrorCode.OK, result);
			return retMsg;
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/savePersonLogo.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg savePersonLogo(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "personId");
			String logo = RequestUtil.get(request, "logo");
			if(StringUtil.isBlank(logo)){
				return new ResponseMsg("缺少参数", ErrorCode.ERROR, null);
			}else{
				boolean logoFlag = true;
				logo = logo.substring(logo.lastIndexOf("/") + 1, logo.length());
				logoFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + logo, Constant.LOGO_FILE_PATH + logo);
				if(logoFlag){
					SdPersonBase personBase = personService.selectPersonBaseById(personId);
					personBase.setLogo(Constant.LOGO_FILE_URL + logo);
					personService.updatePersonBaseById(personBase);
					return new ResponseMsg("保存成功", ErrorCode.OK, null);
				}
				return new ResponseMsg("保存失败", ErrorCode.ERROR, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectPInternshipList.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPInternshipList(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "personId");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			List<Row> resultList = new ArrayList<Row>();
			SdPInternshipExample example = new SdPInternshipExample();
			example.or().andPersonIdEqualTo(personId)
				.andDelCEqualTo(Constant.DEL_NO)
				.andDelPEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdPInternship> pInternshipList = personService.selectPInternshipList(example);
			for(SdPInternship pInternship : pInternshipList){
				Row result = new Row();
				Integer internshipId = pInternship.getInternshipId();
				SdInternship internship = postService.selectInternship(internshipId);
				result.put("postId", pInternship.getpIId());
				result.put("postName", internship.getInternshipName());
				result.put("createTime", DateUtil.DateToString(pInternship.getCreateTime(), DateUtil.FORMAT_ONE));
				Integer status = pInternship.getStatus();
				String statusStr = null;
				switch (status) {
				case 0:
					statusStr = "已申请";
					break;
				case 1:
					statusStr = "已查看";
					break;
				case 2:
					statusStr = "通知面试";
					break;
				case 3:
					statusStr = "已面试";
					break;
				case 4:
					statusStr = "签约上岗";
					break;
				case 5:
					statusStr = "已上班";
					break;
				case 6:
					statusStr = "婉言拒绝";
					break;
				case 7:
					statusStr = "不合适";
					break;
				default:
					break;
				}
				result.put("status", statusStr);
				result.put("source", pInternship.getSource() == Constant.SOURCE_COMPANY ? "企业" : "个人");
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	@RequestMapping(value = { "/selectPParttimeList.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectPParttimeList(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "personId");
			Integer curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			Integer pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			int start = (curPage - 1) * pageSize;
			List<Row> resultList = new ArrayList<Row>();
			SdPParttimeExample example = new SdPParttimeExample();
			example.or().andPersonIdEqualTo(personId)
				.andDelCEqualTo(Constant.DEL_NO)
				.andDelPEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdPParttime> pParttimeList = personService.selectPParttimeList(example);
			for(SdPParttime pParttime : pParttimeList){
				Row result = new Row();
				result.put("postId", pParttime.getpPId());
				Integer parttimeId = pParttime.getParttimeId();
				SdParttime parttime = postService.selectParttime(parttimeId);
				result.put("postName", parttime.getDicParttimeFieldName());
				result.put("createTime", DateUtil.DateToString(pParttime.getCreateTime(), DateUtil.FORMAT_ONE));
				Integer status = pParttime.getStatus();
				String statusStr = null;
				switch (status) {
				case 0:
					statusStr = "已申请";
					break;
				case 1:
					statusStr = "已查看";
					break;
				case 2:
					statusStr = "可上岗";
					break;
				case 3:
					statusStr = "签约上岗";
					break;
				case 4:
					statusStr = "已上岗";
					break;
				case 5:
					statusStr = "爽约";
					break;
				case 6:
					statusStr = "婉言拒绝";
					break;
				case 7:
					statusStr = "不合适";
					break;
				default:
					break;
				}
				result.put("status", statusStr);
				result.put("source", pParttime.getSource() == Constant.SOURCE_COMPANY ? "企业" : "个人");
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}

	@RequestMapping(value = { "/delCompany.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg delCompany(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer companyId = RequestUtil.getInt(request, "companyId", 0);
			if(companyId == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			//删除登录信息
			redisService.del(Constant.COMPANY_TOKEN_PRE + companyId);
			//实习
			SdInternshipExample example1 = new SdInternshipExample();
			example1.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdInternship> internshipList = postService.selectInternshipList(example1);
			if(internshipList != null && internshipList.size() > 0){
				List<Integer> internshipIdList = new ArrayList<Integer>();
				for(SdInternship internship : internshipList){
					internshipIdList.add(internship.getInternshipId());
				}
				//删除个人申请实习记录
				SdPInternship pInternship = new SdPInternship();
				pInternship.setDelC(Constant.DEL_YES);
				pInternship.setDelP(Constant.DEL_YES);
				SdPInternshipExample example2 = new SdPInternshipExample();
				example2.or().andInternshipIdIn(internshipIdList);
				postService.updatePIntenrship(pInternship, example2);
				//删除实习岗位评价
				SdInternshipReview internshipReview = new SdInternshipReview();
				internshipReview.setDel(Constant.DEL_YES);
				SdInternshipReviewExample example8 = new SdInternshipReviewExample();
				example8.or().andDelEqualTo(Constant.DEL_NO)
				.andInternshipIdIn(internshipIdList);
				postService.updateInternshipReview(internshipReview, example8);
				//删除实习岗位收藏
				SdPCollection pCollection = new SdPCollection();
				pCollection.setDel(Constant.DEL_YES);
				SdPCollectionExample example6 = new SdPCollectionExample();
				example6.or().andDelEqualTo(Constant.DEL_NO)
					.andPostFlagEqualTo(Constant.POST_FLAG_INTERNSHIP)
					.andPostIdIn(internshipIdList);
				personService.updatePCollection(pCollection, example6);
				//删除实习岗位
				SdInternship internship = new SdInternship();
				internship.setDel(Constant.DEL_YES);
				postService.updateInternship(internship, example1);
			}
			//兼职
			SdParttimeExample example4 = new SdParttimeExample();
			example4.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdParttime> parttimeList = postService.selectParttimeList(example4);
			if(parttimeList != null && parttimeList.size() > 0){
				List<Integer> parttimeIdList = new ArrayList<Integer>();
				for(SdParttime parttime : parttimeList){
					parttimeIdList.add(parttime.getParttimeId());
				}
				//删除个人申请兼职记录
				SdPParttime pParttime = new SdPParttime();
				pParttime.setDelC(Constant.DEL_YES);
				pParttime.setDelP(Constant.DEL_YES);
				SdPParttimeExample example5 = new SdPParttimeExample();
				example5.or().andParttimeIdIn(parttimeIdList);
				postService.updatePParttime(pParttime, example5);
				//删除兼职岗位评价
				SdParttimeReview parttimeReview = new SdParttimeReview();
				parttimeReview.setDel(Constant.DEL_YES);
				SdParttimeReviewExample example9 = new SdParttimeReviewExample();
				example9.or().andDelEqualTo(Constant.DEL_NO)
				.andParttimeIdIn(parttimeIdList);
				postService.updateParttimeReview(parttimeReview, example9);
				//删除兼职岗位收藏
				SdPCollection pCollection = new SdPCollection();
				pCollection.setDel(Constant.DEL_YES);
				SdPCollectionExample example6 = new SdPCollectionExample();
				example6.or().andDelEqualTo(Constant.DEL_NO)
				.andPostFlagEqualTo(Constant.POST_FLAG_PARTTIME)
				.andPostIdIn(parttimeIdList);
				personService.updatePCollection(pCollection, example6);
				//删除兼职岗位
				SdParttime parttime = new SdParttime();
				parttime.setDel(Constant.DEL_YES);
				postService.updateParttime(parttime, example4);
			}
			
			//删除公司图片
			SdCompanyPhoto companyPhoto = new SdCompanyPhoto();
			companyPhoto.setDel(Constant.DEL_YES);
			SdCompanyPhotoExample example7 = new SdCompanyPhotoExample();
			example7.or().andCompanyIdEqualTo(companyId);
			companyService.updateCompanyPhoto(companyPhoto, example7);
			//删除公司信息
			SdCompany company = new SdCompany();
			company.setCompanyId(companyId);
			company.setDel(Constant.DEL_YES);
			companyService.updateCompanyById(company);
			SdCompanyBase companyBase = new SdCompanyBase();
			companyBase.setCompanyId(companyId);
			companyBase.setDel(Constant.DEL_YES);
			companyService.updateCompanyBaseById(companyBase);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/delPerson.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg delPerson(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer personId = RequestUtil.getInt(request, "personId", 0);
			if(personId == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			//删除登录信息
			redisService.del(Constant.PERSON_TOKEN_PRE + personId);
			//删除收藏的职位
			SdPCollection pCollection = new SdPCollection();
			pCollection.setDel(Constant.DEL_YES);
			SdPCollectionExample example1 = new SdPCollectionExample();
			example1.or().andDelEqualTo(Constant.DEL_NO)
				.andPersonIdEqualTo(personId);
			personService.updatePCollection(pCollection, example1);
			//删除实习岗位
			SdPInternship pInternship = new SdPInternship();
			pInternship.setDelC(Constant.DEL_YES);
			pInternship.setDelP(Constant.DEL_YES);
			SdPInternshipExample example2 = new SdPInternshipExample();
			example2.or().andPersonIdEqualTo(personId);
			postService.updatePIntenrship(pInternship, example2);
			//删除兼职岗位
			SdPParttime pParttime = new SdPParttime();
			pParttime.setDelC(Constant.DEL_YES);
			pParttime.setDelP(Constant.DEL_YES);
			SdPParttimeExample example3 = new SdPParttimeExample();
			example3.or().andPersonIdEqualTo(personId);
			postService.updatePParttime(pParttime, example3);
			//删除对实习岗位的评价
			SdInternshipReview internshipReview = new SdInternshipReview();
			internshipReview.setDel(Constant.DEL_YES);
			SdInternshipReviewExample example11 = new SdInternshipReviewExample();
			example11.or().andDelEqualTo(Constant.DEL_NO)
				.andPersionIdEqualTo(personId);
			postService.updateInternshipReview(internshipReview, example11);
			//删除对兼职岗位的评价
			SdParttimeReview parttimeReview = new SdParttimeReview();
			parttimeReview.setDel(Constant.DEL_YES);
			SdParttimeReviewExample example10 = new SdParttimeReviewExample();
			example10.or().andDelEqualTo(Constant.DEL_NO)
				.andPersionIdEqualTo(personId);
			postService.updateParttimeReview(parttimeReview, example10);
			//删除个人风采照片
			SdPersonPhoto personPhoto = new SdPersonPhoto();
			personPhoto.setDel(Constant.DEL_YES);
			SdPersonPhotoExample example4 = new SdPersonPhotoExample();
			example4.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updatePhoto(personPhoto, example4);
			//删除证书照片
			SdCertificate certificate = new SdCertificate();
			certificate.setDel(Constant.DEL_YES);
			SdCertificateExample example5 = new SdCertificateExample();
			example5.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updateCertificate(certificate, example5);
			//删除教育经历
			SdEduExp eduExp = new SdEduExp();
			eduExp.setDel(Constant.DEL_YES);
			SdEduExpExample example6 = new SdEduExpExample();
			example6.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updateEduExp(eduExp, example6);
			//删除校内经历
			SdInExp inExp = new SdInExp();
			inExp.setDel(Constant.DEL_YES);
			SdInExpExample example7 = new SdInExpExample();
			example7.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updateInExp(inExp, example7);
			//删除校外经历
			SdOutExp outExp = new SdOutExp();
			outExp.setDel(Constant.DEL_YES);
			SdOutExpExample example8 = new SdOutExpExample();
			example8.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updateOutExp(outExp, example8);
			//删除个人标签
			SdLabel label = new SdLabel();
			label.setDel(Constant.DEL_YES);
			SdLabelExample example9 = new SdLabelExample();
			example9.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			personService.updateLabel(label, example9);
			//删除个人信息
			SdPerson person = new SdPerson();
			person.setPersonId(personId);
			person.setDel(Constant.DEL_YES);
			personService.updatePersonById(person);
			SdPersonBase personBase = new SdPersonBase();
			personBase.setPersonId(personId);
			personBase.setDel(Constant.DEL_YES);
			personService.updatePersonBaseById(personBase);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/editCompany.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg editCompany(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer companyId = RequestUtil.getInt(request, "companyId", 0);
			String companyName = RequestUtil.get(request, "companyName");
			Integer dicFieldId = RequestUtil.getInt(request, "dicFieldId", 0);
			String website = RequestUtil.get(request, "website");
			Integer districtId = RequestUtil.getInt(request, "districtId", 0);
			String location = RequestUtil.get(request, "location");
			String email = RequestUtil.get(request, "email");
			String tel = RequestUtil.get(request, "tel");
			String intro = RequestUtil.get(request, "intro");
			if(!StringUtil.isBlank(email) && !StringUtil.isEmail(email)){
				return new ResponseMsg("邮箱格式错误", ErrorCode.ERROR, null);
			}
			if(!StringUtil.isBlank(tel) && !(StringUtil.isMobile(tel) || StringUtil.isPhone(tel))){
				return new ResponseMsg("手机号格式错误", ErrorCode.ERROR, null);
			}
			SdCompany company = null;
			SdCompanyBase companyBase = null;
			if(companyId == 0){//新增
				SdCompanyBaseExample example = new SdCompanyBaseExample();
				example.or().andTelEqualTo(tel).andDelEqualTo(Constant.DEL_NO);
				int count = companyService.countCompanyBaseByExample(example);
				if(count > 0){
					return new ResponseMsg("此手机号已占用", ErrorCode.ERROR, null);
				}else{
					company = new SdCompany();
					companyBase = new SdCompanyBase();
				}
			}else{//修改
				company = companyService.selectCompanyById(companyId);
				companyBase = companyService.selectCompanyBaseById(companyId);
			}
			if(dicFieldId != 0){
				company.setDicFieldId(dicFieldId);
				companyBase.setDicFieldId(dicFieldId);
				SdDicCompanyFieldExample dicCompanyFieldExample = new SdDicCompanyFieldExample();
				dicCompanyFieldExample.or().andDicFieldIdEqualTo(dicFieldId);
				List<SdDicCompanyField> dicCompanyFieldList = dicService.selectByExample(dicCompanyFieldExample);
				if(dicCompanyFieldList.size() > 0){
					SdDicCompanyField dicCompanyField = dicCompanyFieldList.get(0);
					String dicFieldName = dicCompanyField.getDicFieldName();
					company.setDicFieldName(dicFieldName);
					companyBase.setDicFieldName(dicFieldName);
				}
			}
			if(!StringUtil.isBlank(website)){
				company.setWebsite(website);
			}
			if(districtId != 0){
				company.setDistrictId(districtId);
				Integer provinceId = (districtId / 10000) * 10000;
				Integer cityId = (districtId / 100) * 100;
				String provinceStr = "";
				String cityStr = "";
				String districtStr = "";
				//省
				SdDicDistrict dicDistrict = dicService.selectDistrictById(provinceId);
				if(dicDistrict != null){
					provinceStr = dicDistrict.getDicDistrict();
				}
				//市
				dicDistrict = dicService.selectDistrictById(cityId);
				if(dicDistrict != null){
					cityStr = dicDistrict.getDicDistrict();
				}
				//区
				dicDistrict = dicService.selectDistrictById(districtId);
				if(dicDistrict != null){
					districtStr = dicDistrict.getDicDistrict();
				}
				company.setDistrict(provinceStr + " " + cityStr + " " + districtStr);
			}
			if(!StringUtil.isBlank(location)){
				company.setLocation(location);
			}
			if(!StringUtil.isBlank(email)){
				company.setEmail(email);
				companyBase.setEmail(email);
			}
			if(!StringUtil.isBlank(intro)){
				company.setIntro(intro);
			}
			if(companyId == 0){//新增
				companyId = sequenceService.nextSequence(TableConstant.SD_COMPANY);
				company.setCompanyId(companyId);
				company.setCompanyName(companyName);
				company.setTel(tel);
				companyBase.setCompanyId(companyId);
				companyBase.setCompanyName(companyName);
				companyBase.setTel(tel);
				companyBase.setPwd(MD5Util.encodeByMD5(Constant.DEFAULT_PWD));
				companyBase.setStatus(1);//后台添加
				Date createDate = new Date();
				company.setCreateDate(createDate);
				companyBase.setCreateDate(createDate);
				companyService.insertCompany(company);
				companyService.insertCompanyBase(companyBase);
			}else{//修改
				companyService.updateCompanyById(company);
			}
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/editPerson.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg editPerson(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer personId = RequestUtil.getInt(request, "personId");
			String personName = RequestUtil.get(request, "personName");
			Integer personGender = RequestUtil.getInt(request, "personGender", 1);//默认男
			String birthday = RequestUtil.get(request, "birthday");
			String tel = RequestUtil.get(request, "tel");
			String email = RequestUtil.get(request, "email");
			Integer districtId = RequestUtil.getInt(request, "districtId");
			Integer postFlag = RequestUtil.getInt(request, "postFlag", Constant.POST_FLAG_PARTTIME);//1实习2兼职,默认2
			Integer dicFieldId = RequestUtil.getInt(request, "dicFieldId");
			Integer universityId = RequestUtil.getInt(request, "universityId");
			String college = RequestUtil.get(request, "college");
			String major = RequestUtil.get(request, "major");
			String admissionDate = RequestUtil.get(request, "admissionDate");
			Integer dicEducationId = RequestUtil.getInt(request, "dicEducationId");
			String selfEvaluation = RequestUtil.get(request, "selfEvaluation");
			if(!StringUtil.isBlank(email) && !StringUtil.isEmail(email)){
				return new ResponseMsg("邮箱格式错误", ErrorCode.ERROR, null);
			}
			if(StringUtil.isBlank(tel) && !(StringUtil.isMobile(tel) || StringUtil.isPhone(tel))){
				return new ResponseMsg("手机号格式错误", ErrorCode.ERROR, null);
			}
			SdPerson person = null;
			SdPersonBase personBase = null;
			if(personId == null){//新增
				person = new SdPerson();
				personBase = new SdPersonBase();
				if(StringUtil.isBlank(personName) || StringUtil.isBlank(tel)){
					return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				}else{
					SdPersonBaseExample example = new SdPersonBaseExample();
					example.or().andTelEqualTo(tel).andDelEqualTo(Constant.DEL_NO);
					int count = personService.countPersonBaseByExample(example);
					if(count > 0){
						return new ResponseMsg("此手机号已注册！",ErrorCode.ERROR, null);
					}
				}
				
			}else{//修改
				person = personService.selectPersonById(personId);
				personBase = personService.selectPersonBaseById(personId);
			}
			person.setPersonGender(personGender);
			if(!StringUtil.isBlank(birthday)){
				person.setBirthday(DateUtil.StringtoDate(birthday, DateUtil.EXTRA_DATE_FORMAT));
			}
			if(!StringUtil.isBlank(email)){
				personBase.setEmail(email);
				person.setEmail(email);
			}
			if(districtId != null){
				person.setDistrictId(districtId);
				Integer provinceId = (districtId / 10000) * 10000;
				Integer cityId = (districtId / 100) * 100;
				String provinceStr = "";
				String cityStr = "";
				String districtStr = "";
				//省
				SdDicDistrict dicDistrict = dicService.selectDistrictById(provinceId);
				if(dicDistrict != null){
					provinceStr = dicDistrict.getDicDistrict();
				}
				//市
				dicDistrict = dicService.selectDistrictById(cityId);
				if(dicDistrict != null){
					cityStr = dicDistrict.getDicDistrict();
				}
				//区
				dicDistrict = dicService.selectDistrictById(districtId);
				if(dicDistrict != null){
					districtStr = dicDistrict.getDicDistrict();
				}
				person.setDistrict(provinceStr + " " + cityStr + " " + districtStr);
			}
			person.setPostFlag(postFlag);
			if(dicFieldId != null){
				person.setDicFieldId(dicFieldId);
				if(Constant.POST_FLAG_INTERNSHIP == postFlag){//
					SdDicInternshipField field = dicService.selectInternshipField(dicFieldId);
					person.setDicFieldName(field.getDicFieldName());
				}else if(Constant.POST_FLAG_PARTTIME == postFlag){//
					SdDicParttimeField field = dicService.selectParttimeField(dicFieldId);
					person.setDicFieldName(field.getDicFieldName());
				}
			}
			if(universityId != null){
				personBase.setUniversityId(universityId);
				person.setUniversityId(universityId);
				SdDicUniversity university = dicService.selectUniversity(universityId);
				if(university != null){
					personBase.setUniversity(university.getDicUniversityName());
					person.setUniversity(university.getDicUniversityName());
				}
			}
			if(!StringUtil.isBlank(college)){
				person.setCollege(college);
			}
			if(!StringUtil.isBlank(major)){
				person.setMajor(major);
			}
			if(!StringUtil.isBlank(admissionDate)){
				person.setAdmissionDate(DateUtil.StringtoDate(admissionDate, DateUtil.EXTRA_DATE_FORMAT));
			}
			if(!StringUtil.isBlank(selfEvaluation)){
				person.setSelfEvaluation(selfEvaluation);;
			}
			if(dicEducationId != null){
				person.setDicEducationId(dicEducationId);
				SdDicEducation dicEducation = dicService.selectDicEducation(dicEducationId);
				if(dicEducation != null){
					person.setDicEducationName(dicEducation.getDicEducationName());
				}
			}
			if(personId == null){//新增
				personId = sequenceService.nextSequence(TableConstant.SD_PERSON);
				person.setPersonId(personId);
				personBase.setPersonId(personId);
				personBase.setPersonName(personName);
				person.setPersonName(personName);
				person.setTel(tel);
				personBase.setTel(tel);
				personBase.setPwd(MD5Util.encodeByMD5(Constant.DEFAULT_PWD));
				Date createDate = new Date();
				person.setCreateTime(createDate);
				personBase.setCreateTime(createDate);
				personService.insertPerson(person);
				personService.insertPersonBase(personBase);
			}else{//修改
				personService.updatePersonBaseById(personBase);
				personService.updatePersonById(person);
			}
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/saveCompanyPhoto.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg saveCompanyPhoto(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer companyId = RequestUtil.getInt(request, "companyId", 0);
			String photo = RequestUtil.get(request, "photo");
			if(companyId == 0 || StringUtil.isBlank(photo)){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			photo = photo.substring(photo.lastIndexOf("/") + 1, photo.length());
			boolean cardFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + photo, Constant.PHOTO_FILE_PATH + photo);
			if(cardFlag){
				SdCompanyPhoto companyPhoto = new SdCompanyPhoto();
				companyPhoto.setCompanyId(companyId);
				companyPhoto.setCompanyPhotoUrl(Constant.PHOTO_FILE_URL + photo);
				companyPhoto.setCreateTime(new Date());
				companyService.insertCompanyPhoto(companyPhoto);
			}
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/delCompanyPhoto.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg delCompanyPhoto(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer companyPhotoId = RequestUtil.getInt(request, "companyPhotoId", 0);
			if(companyPhotoId == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);	
			}
			SdCompanyPhoto companyPhoto = new SdCompanyPhoto();
			companyPhoto.setCompanyPhotoId(companyPhotoId);
			companyPhoto.setDel(Constant.DEL_YES);
			companyService.updateCompanyPhoto(companyPhoto);
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/checkTelAdmin.json" })
	@ResponseBody
	public ResponseMsg checkTelAdmin(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		String tel = RequestUtil.get(request, "tel");
		Integer roleFlag = RequestUtil.getInt(request, "roleFlag");
		if(StringUtil.isBlank(tel)){
			return new ResponseMsg("缺少必要参数！", ErrorCode.ERROR, null);
		}
		if(!StringUtil.isMobile(tel) && !StringUtil.isPhone(tel)){
			return new ResponseMsg("手机号格式错误", ErrorCode.ERROR, null);
		}
		int count = Constant.DEFAULT_INTEGER;
		if(Constant.SOURCE_PERSON == roleFlag){//个人
			SdPersonBaseExample example = new SdPersonBaseExample();
			example.or().andTelEqualTo(tel).andDelEqualTo(Constant.DEL_NO);
			count = personService.countPersonBaseByExample(example);
		}else if(Constant.SOURCE_COMPANY == roleFlag){//企业
			SdCompanyBaseExample example = new SdCompanyBaseExample();
			example.or().andTelEqualTo(tel).andDelEqualTo(Constant.DEL_NO);
			count = companyService.countCompanyBaseByExample(example);	
		}
		if(count != 0){
			retMsg = new ResponseMsg("此手机号已注册！",ErrorCode.OK, false);
		}else{
			retMsg = new ResponseMsg("",ErrorCode.OK, true);
		}
		return retMsg;
	}
	
	
	

	@RequestMapping(value = { "/statistics1.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg statistics1(HttpServletRequest request, HttpServletResponse response) {
		try{
			Row result = new Row();
			String startDate = RequestUtil.get(request, "startDate");
			String endDate = RequestUtil.get(request, "endDate");
			DateUtil du = new DateUtil();
			if(StringUtil.isBlank(startDate)){
				startDate = du.getPreviousYearFirst();
			}
			if(StringUtil.isBlank(endDate)){
				endDate = du.getNextYearEnd();
			}
			Date start = DateUtil.StringtoDate(startDate, DateUtil.EXTRA_DATE_FORMAT);
			Date end = DateUtil.StringtoDate(endDate, DateUtil.EXTRA_DATE_FORMAT);
			//指定时间段内的注册人数
			SdPersonBaseExample example1 = new SdPersonBaseExample();
			example1.or().andCreateTimeBetween(start, end)
				.andDelEqualTo(Constant.DEL_NO);
			int personCount = personService.countPersonBaseByExample(example1);
			result.put("personCount", personCount);
			//指定时间段内注册人数 按照学历分布
			List<Row> educationList = new ArrayList<Row>();
			SdDicEducationExample example2 = new SdDicEducationExample();
			example2.or().andDelEqualTo(Constant.DEL_NO);
			List<SdDicEducation> dicEducationList = dicService.selectByExample(example2);
			SdPersonExample example3 = null;
			for(SdDicEducation dicEducation : dicEducationList){
				example3 = new SdPersonExample();
				Integer dicEducationId = dicEducation.getDicEducationId();
				String dicEducationName = dicEducation.getDicEducationName();
				example3.or().andDicEducationIdEqualTo(dicEducationId)
					.andDelEqualTo(Constant.DEL_NO)
					.andCreateTimeBetween(start, end);
				int educationCount = personService.countPersonByExample(example3);
				if(educationCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicEducationName", dicEducationName);
					resultRow.put("educationCount", educationCount);
					educationList.add(resultRow);
				}
			}
			result.put("educationList", educationList);
			//指定时间段内注册人数 按照地区分布
			List<Row> districtList = new ArrayList<Row>();
			SdDicDistrictExample example4 = new SdDicDistrictExample();
			example4.or().andDelEqualTo(Constant.DEL_NO).andLevelEqualTo(Constant.DISTRICT_PROVINCE);
			List<SdDicDistrict> dicDistrictList = dicService.selectByExample(example4);
			SdPersonExample example5 = null;
			for(SdDicDistrict dicDistrict : dicDistrictList){
				example5 = new SdPersonExample();
				Integer dicDistrictId = dicDistrict.getDicDistrictId();
				String dicDistrictName = dicDistrict.getDicDistrict();
				Integer disId = dicDistrictId / 10000;
				Integer mindisId =  disId * 10000;
				Integer maxdisId =  disId * 10000 + 9999;
				example5.or().andDistrictIdBetween(mindisId, maxdisId)
					.andDelEqualTo(Constant.DEL_NO)
					.andCreateTimeBetween(start, end);
				int districtCount = personService.countPersonByExample(example5);
				if(districtCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicDistrictName", dicDistrictName);
					resultRow.put("districtCount", districtCount);
					districtList.add(resultRow);
				}
			}
			result.put("districtList", districtList);
			//指定时间段内注册人数 按照实习岗位领域分布
			List<Row> internshipList = new ArrayList<Row>();
			SdDicInternshipFieldExample example6 = new SdDicInternshipFieldExample();
			example6.or().andDelEqualTo(Constant.DEL_NO);
			example6.setOrderByClause("category");
			List<SdDicInternshipField> dicInternshipFieldList = dicService.selectByExample(example6);
			SdPersonExample example7 = null;
			for(SdDicInternshipField dicField : dicInternshipFieldList){
				example7 = new SdPersonExample();
				Integer dicFieldId = dicField.getDicFieldId();
				String dicFieldName = dicField.getDicFieldName();
				String category = dicField.getCategory();
				example7.or().andDicFieldIdEqualTo(dicFieldId)
					.andDelEqualTo(Constant.DEL_NO)
					.andCreateTimeBetween(start, end);
				int internshipCount = personService.countPersonByExample(example7);
				if(internshipCount > 0){
					Row resultRow = new Row();
					resultRow.put("category", category);
					resultRow.put("dicFieldName", dicFieldName);
					resultRow.put("internshipCount", internshipCount);
					internshipList.add(resultRow);
				}
			}
			result.put("internshipList", internshipList);
			//指定时间段内注册人数 按照兼职岗位领域分布
			List<Row> parttimeList = new ArrayList<Row>();
			SdDicParttimeFieldExample example8 = new SdDicParttimeFieldExample();
			example8.or().andDelEqualTo(Constant.DEL_NO);
			List<SdDicParttimeField> dicParttimeFieldList = dicService.selectByExample(example8);
			SdPersonExample example9 = null;
			for(SdDicParttimeField dicField : dicParttimeFieldList){
				example9 = new SdPersonExample();
				Integer dicFieldId = dicField.getDicFieldId();
				String dicFieldName = dicField.getDicFieldName();
				example9.or().andDicFieldIdEqualTo(dicFieldId)
					.andDelEqualTo(Constant.DEL_NO)
					.andCreateTimeBetween(start, end);
				int parttimeCount = personService.countPersonByExample(example9);
				if(parttimeCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicFieldName", dicFieldName);
					resultRow.put("parttimeCount", parttimeCount);
					parttimeList.add(resultRow);
				}
			}
			result.put("parttimeList", parttimeList);
			//指定时间段内，商家的注册数
			SdCompanyBaseExample example10 = new SdCompanyBaseExample();
			example10.or().andDelEqualTo(Constant.DEL_NO)
				.andCreateDateBetween(start, end);
			Integer companyCount = companyService.countCompanyBaseByExample(example10);
			result.put("companyCount", companyCount);
			//指定时间段内，商家的注册数 按照公司领域分配
			List<Row> companyFieldList = new ArrayList<Row>();
			SdDicCompanyFieldExample example11 = new SdDicCompanyFieldExample();
			example11.or().andDelEqualTo(Constant.DEL_NO);
			List<SdDicCompanyField> fieldList = dicService.selectByExample(example11);
			SdCompanyExample example12 = null;
			for(SdDicCompanyField companyField : fieldList){
				example12 = new SdCompanyExample();
				Integer fieldId = companyField.getDicFieldId();
				String fieldName = companyField.getDicFieldName();
				example12.or().andDicFieldIdEqualTo(fieldId)
					.andDelEqualTo(Constant.DEL_NO)
					.andCreateDateBetween(start, end);
				Integer fieldCount = companyService.countCompanyByExample(example12);
				if(fieldCount > 0){
					Row resultRow = new Row();
					resultRow.put("fieldName", fieldName);
					resultRow.put("fieldCount", fieldCount);
					companyFieldList.add(resultRow);
				}
			}
			result.put("companyFieldList", companyFieldList);
			//指定时间段内，新增实习岗位数
			SdInternshipExample example13 = new SdInternshipExample();
			example13.or().andCreateDateBetween(start, end)
				.andDelEqualTo(Constant.DEL_NO);
			Integer intenrshipCount = postService.countInternship(example13);
			result.put("intenrshipCount", intenrshipCount);
			//指定时间段内，新增实习岗位数 按照地区分布
			List<Row> internshipDistrictList = new ArrayList<Row>();
			SdInternshipExample example14 = null;
			for(SdDicDistrict dicDistrict : dicDistrictList){
				example5 = new SdPersonExample();
				Integer dicDistrictId = dicDistrict.getDicDistrictId();
				String dicDistrictName = dicDistrict.getDicDistrict();
				Integer disId = dicDistrictId / 10000;
				Integer mindisId =  disId * 10000;
				Integer maxdisId =  disId * 10000 + 9999;
				example14 = new SdInternshipExample();
				example14.or().andCreateDateBetween(start, end)
					.andDelEqualTo(Constant.DEL_NO)
					.andDistrictIdBetween(mindisId, maxdisId);
				Integer intenrshipDistrictCount = postService.countInternship(example14);
				if(intenrshipDistrictCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicDistrictName", dicDistrictName);
					resultRow.put("intenrshipDistrictCount", intenrshipDistrictCount);
					internshipDistrictList.add(resultRow);
				}
			}
			result.put("internshipDistrictList", internshipDistrictList);
			//指定时间段内，新增实习岗位数 按照岗位领域分布
			List<Row> internshipFieldList = new ArrayList<Row>();
			SdInternshipExample example15 = null;
			for(SdDicInternshipField dicField : dicInternshipFieldList){
				Integer dicFieldId = dicField.getDicFieldId();
				String dicFieldName = dicField.getDicFieldName();
				example15 = new SdInternshipExample();
				example15.or().andDicInternshipFieldIdEqualTo(dicFieldId)
					.andCreateDateBetween(start, end)
					.andDelEqualTo(Constant.DEL_NO);
				int internshipCount = postService.countInternship(example15);
				if(internshipCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicFieldName", dicFieldName);
					resultRow.put("internshipCount", internshipCount);
					internshipFieldList.add(resultRow);
				}
			}
			result.put("internshipFieldList", internshipFieldList);
			//指定时间段内，新增兼职岗位数
			SdParttimeExample example16 = new SdParttimeExample();
			example16.or().andCreateTimeBetween(start, end)
				.andDelEqualTo(Constant.DEL_NO);
			Integer parttimeCount = postService.countParttime(example16);
			result.put("parttimeCount", parttimeCount);
			//指定时间段内，新增兼职岗位数 按照地区分布
			List<Row> parttimeDistrictList = new ArrayList<Row>();
			SdParttimeExample example17 = null;
			for(SdDicDistrict dicDistrict : dicDistrictList){
				example5 = new SdPersonExample();
				Integer dicDistrictId = dicDistrict.getDicDistrictId();
				String dicDistrictName = dicDistrict.getDicDistrict();
				Integer disId = dicDistrictId / 10000;
				Integer mindisId =  disId * 10000;
				Integer maxdisId =  disId * 10000 + 9999;
				example17 = new SdParttimeExample();
				example17.or().andCreateTimeBetween(start, end)
					.andDelEqualTo(Constant.DEL_NO)
					.andDistrictIdBetween(mindisId, maxdisId);
				Integer parttimeDistrictCount = postService.countParttime(example17);
				if(parttimeDistrictCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicDistrictName", dicDistrictName);
					resultRow.put("parttimeDistrictCount", parttimeDistrictCount);
					parttimeDistrictList.add(resultRow);
				}
			}
			result.put("parttimeDistrictList", parttimeDistrictList);
			//指定时间段内，新增兼职岗位数 按照岗位领域分布
			List<Row> parttimeFieldList = new ArrayList<Row>();
			SdParttimeExample example18 = null;
			for(SdDicParttimeField dicField : dicParttimeFieldList){
				Integer dicFieldId = dicField.getDicFieldId();
				String dicFieldName = dicField.getDicFieldName();
				example18 = new SdParttimeExample();
				example18.or().andDicParttimeFieldIdEqualTo(dicFieldId)
					.andCreateTimeBetween(start, end)
					.andDelEqualTo(Constant.DEL_NO);
				int parttimeFieldCount = postService.countParttime(example18);
				if(parttimeFieldCount > 0){
					Row resultRow = new Row();
					resultRow.put("dicFieldName", dicFieldName);
					resultRow.put("parttimeFieldCount", parttimeFieldCount);
					parttimeFieldList.add(resultRow);
				}
			}
			result.put("parttimeFieldList", parttimeFieldList);
			DecimalFormat format = new DecimalFormat("0.00");
			//个人投递成功率
			SdPInternshipExample example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_PERSON);
			int count1 = personService.countPInternship(example19);
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_PERSON)
				.andStatusEqualTo(Constant.INTERNSHIP_STATUS_WORKED);
			int count2 = personService.countPInternship(example19);
			Double ratio1 = 0.0;
			if(count1 != 0){
				ratio1 = ((double) count2/count1);
			}
			result.put("personRatio", format.format(ratio1));
			//企业邀请成功率
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_COMPANY);
			int count3 = personService.countPInternship(example19);
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_COMPANY)
				.andStatusEqualTo(Constant.INTERNSHIP_STATUS_WORKED);
			int count4 = personService.countPInternship(example19);
			Double ratio2 = 0.0;
			if(count3 != 0){  //
				ratio2 = ((double) count4/count3);
			}
			result.put("companyRatio", format.format(ratio2));
			//个人投递简历查看率
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_PERSON);
			int count5 = personService.countPInternship(example19);
			List<Integer> statusList = new ArrayList<Integer>();
			statusList.add(Constant.INTERNSHIP_STATUS_CHECKED);
			statusList.add(Constant.INTERNSHIP_STATUS_INFORM);
			statusList.add(Constant.INTERNSHIP_STATUS_INTERVIEWED);
			statusList.add(Constant.INTERNSHIP_STATUS_REJECT);
			statusList.add(Constant.INTERNSHIP_STATUS_SIGN);
			statusList.add(Constant.INTERNSHIP_STATUS_UNFIT);
			statusList.add(Constant.INTERNSHIP_STATUS_WORKED);
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_PERSON)
				.andStatusIn(statusList);
			int count6 = personService.countPInternship(example19);
			Double ratio3 = 0.0;
			if(count5 != 0){
				ratio3 = ((double) count6/count5);
			}
			result.put("checkRatio", format.format(ratio3));
			//企业邀请参加面试率
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_COMPANY);
			int count7 = personService.countPInternship(example19);
			statusList = new ArrayList<Integer>();
			statusList.add(Constant.INTERNSHIP_STATUS_INFORM);
			statusList.add(Constant.INTERNSHIP_STATUS_INTERVIEWED);
			statusList.add(Constant.INTERNSHIP_STATUS_REJECT);
			statusList.add(Constant.INTERNSHIP_STATUS_SIGN);
			statusList.add(Constant.INTERNSHIP_STATUS_UNFIT);
			statusList.add(Constant.INTERNSHIP_STATUS_WORKED);
			example19 = new SdPInternshipExample();
			example19.or().andCreateTimeBetween(start, end)
				.andSourceEqualTo(Constant.SOURCE_COMPANY)
				.andStatusIn(statusList);
			int count8 = personService.countPInternship(example19);
			Double ratio4 = 0.0;
			if(count7 != 0){
				ratio4 = ((double) count8/count7);
			}
			result.put("interviewRatio", format.format(ratio4));
			return new ResponseMsg("查询成功", ErrorCode.OK, result);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/delPost.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg delPost(HttpServletRequest request, HttpServletResponse response) {
		try {
			Integer postId = RequestUtil.getInt(request, "postId", 0);
			Integer postFlag = RequestUtil.getInt(request, "postFlag", 0);
			if(postId == 0 || postFlag == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			if(Constant.POST_FLAG_INTERNSHIP == postFlag){//实习
				SdInternship internship = postService.selectInternship(postId);
				internship.setDel(Constant.DEL_YES);
				postService.updateInternship(internship);
			}else if(Constant.POST_FLAG_PARTTIME == postFlag){//兼职
				SdParttime parttime = postService.selectParttime(postId);
				parttime.setDel(Constant.DEL_YES);
				postService.updateParttime(parttime);//
			}
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
			}catch(Exception e){
				e.printStackTrace();
				return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
			}
	
	}
	
	
	
	@RequestMapping(value = { "/resetPwd.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg resetPwd(HttpServletRequest request, HttpServletResponse response) {
		try{
			String oldPwd = RequestUtil.get(request, "oldPwd");
			String newPwd = RequestUtil.get(request, "newPwd");
			String admin_name = Constant.userName;
			SdAdminExample example = new SdAdminExample();
			example.or().andAdminNameEqualTo(admin_name)
				.andAdminPwdEqualTo(MD5Util.encodeByMD5(oldPwd));
			List<SdAdmin> admin_list = adminService.selectAdmin(example);
			if(admin_list.size() > 0){
				SdAdmin admin = admin_list.get(0);
				admin.setAdminPwd(MD5Util.encodeByMD5(newPwd));
				adminService.updateAdmin(admin);
				return new ResponseMsg("重置密码成功", ErrorCode.OK, null);
			}else{
				return new ResponseMsg("原密码错误", ErrorCode.ERROR, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/logout.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg logout(HttpServletRequest request, HttpServletResponse response) {
		try{
			redisService.del(Constant.SERVER_TOKEN_PRE);
			return new ResponseMsg("注销成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	

	
}
